package com.zh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.common.BaseResponse;
import com.zh.common.ErrorCode;
import com.zh.common.ResultUtils;
import com.zh.domain.dto.bug.AddBugCommentRequest;
import com.zh.domain.dto.bug.PageBugCommentRequest;
import com.zh.domain.dto.task.AddTaskCommentRequest;
import com.zh.domain.dto.task.PageTaskCommentRequest;
import com.zh.domain.vo.bug.BugCommentVo;
import com.zh.domain.vo.task.TaskCommentVo;
import com.zh.exception.ThrowUtils;
import com.zh.service.BugCommentsService;
import com.zh.service.TaskCommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "BugCommentsController", value = "缺陷评论控制器")
@RestController
@RequestMapping("/bug-comment")
public class BugCommentsController {
    @Resource
    private BugCommentsService bugCommentsService;

    @PostMapping
    @ApiOperation(value = "addBugComment", notes = "添加缺陷评论")
    public BaseResponse<Boolean> addBugComment(@RequestBody AddBugCommentRequest addBugCommentRequest) {
        ThrowUtils.throwIf(null == addBugCommentRequest, ErrorCode.PARAMS_ERROR);
        Boolean result = bugCommentsService.addBugComment(addBugCommentRequest);
        return ResultUtils.success(result);
    }

    @PostMapping("/page")
    @ApiOperation(value = "pageBugComment", notes = "分页查询缺陷评论")
    public BaseResponse<Page<BugCommentVo>> pageBugComment(@RequestBody PageBugCommentRequest pageBugCommentRequest) {
        ThrowUtils.throwIf(null == pageBugCommentRequest, ErrorCode.PARAMS_ERROR);
        Page<BugCommentVo> result = bugCommentsService.pageBugComment(pageBugCommentRequest);
        return ResultUtils.success(result);
    }

    @DeleteMapping
    @ApiOperation(value = "deleteBugComment", notes = "删除缺陷评论")
    public BaseResponse<Boolean> deleteBugComment(Integer id) {
        boolean success = bugCommentsService.removeById(id);
        return ResultUtils.success(success);
    }
}
